<html>
<head>
  <title>git</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="Evernote Windows/303788 (zh-CN, DDL); Windows/6.1.7601 Service Pack 1 (Win64);"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="339"/>
<h1>git</h1>

<div>
<span><div><span style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/"></a><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/">http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/</a></span></div><div><a href="http://blog.jobbole.com/25808/"></a><a href="http://blog.jobbole.com/25808/">http://blog.jobbole.com/25808/</a></div><div><a href="http://blog.jobbole.com/50603/">http://blog.jobbole.com/50603/</a></div><div><span style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span style="color: rgb(255, 0, 0);">存疑：</span></span></div><div><span style="color: rgb(255, 0, 0);">1 git rm删除的是哪里的文件？版本库还是暂存区（猜测是版本库，因为恢复此命令删除的文件用checkout不起作用）？为什么还需要commit？与rm后add再commit有什么区别？</span></div><div><span style="color: rgb(255, 0, 0);">2 commit到底做了什么？</span></div><div><span style="color: rgb(255, 0, 0);">3 push到底做了什么？commit和push的区别?</span></div><div><span style="color: rgb(255, 0, 0);">4 远程仓库的概念很模糊</span></div><div><span style="color: rgb(255, 0, 0);">5 需不需要创建远程分支？远程分支实际的作用是什么？</span></div><div><br/></div><div><b>1 创建版本库</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">什么是版本库呢？版本库又名仓库，英文名</span><strong style="font-weight: bold; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">repository</strong><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，你可以简单理解成一个目录，这个目录里面的所有文件都可以被Git管理起来，每个文件的修改、删除，Git都能跟踪，以便任何时刻都可以追踪历史，或者在将来某个时刻可以“还原”</span></div><div><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">所以，创建一个版本库非常简单，首先，选择一个合适的地方，创建一个空目录：</p><pre style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>mkdir learngit
<span style="color: rgb(0, 128, 128);">$ </span>cd learngit
<span style="color: rgb(0, 128, 128);">$ </span>pwd
/<span style="color: rgb(0, 153, 153);">Users</span>/michael/learngit
</code></pre><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">pwd</code>命令用于显示当前目录。在我的Mac上，这个仓库位于<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">/Users/michael/learngit</code>。</p><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span style="color: red;">如果你使用Windows系统，为了避免遇到各种莫名其妙的问题，请确保目录名（包括父目录）不包含中文。</span></p><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">第二步，通过<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git init</code>命令把这个目录变成Git可以管理的仓库：</p><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(68, 68, 68);"><code><span style="color: rgb(0, 128, 128);">$ </span>git init</code></span></span><div><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(0, 153, 153);">Initialized</span><span style="color: rgb(68, 68, 68);"> empty </span><span style="color: rgb(0, 153, 153);">Git</span><span style="color: rgb(68, 68, 68);"> repository </span><span style="color: rgb(51, 51, 51); font-weight: bold;">in</span><span style="color: rgb(68, 68, 68);"> /</span><span style="color: rgb(0, 153, 153);">Users</span><span style="color: rgb(68, 68, 68);">/michael/learngit/.git/</span></span></div></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">瞬间Git就把仓库建好了，而且告诉你是一个空的仓库（empty Git repository），细心的读者可以发现当前目录下多了一个</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">.git</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">的目录，这个目录是Git来跟踪管理版本库的，没事千万不要手动修改这个目录里面的文件，不然改乱了，就把Git仓库给破坏了。</span></span></span></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">如果你没有看到</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">.git</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">目录，那是因为这个目录默认是隐藏的，用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">ls -ah</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">命令就可以看见。</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><br/></span></span></span></div><div><b>2 添加文件到git仓库</b></div><div><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">添加文件到Git仓库，分两步：</p><ul style="margin: 15px 0px; padding-left: 30px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><li><p style="margin: 0px 0px 15px; word-wrap: break-word; white-space: pre-wrap;"><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">第一步，使用命令</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git add &lt;file&gt;</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">，注意，可反复多次使用，添加多个文件；</span></span></span></p></li><li><div style="margin: 0px 0px 15px;"><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">第二步，使用命令</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git commit</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">，完成。  </span></span></span><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code>$ git <span style="color: rgb(51, 51, 51); font-weight: bold;">commit</span> -m <span style="color: rgb(221, 17, 68);">&quot;注释内容&quot;</span></code></div></div></li></ul></div><div><b> </b> <code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git commit</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令，</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">-m</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">后面输入的是本次提交的说明，可以输入任意内容，当然最好是有意义的，这样你就能从历史记录里方便地找到改动记录</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">为什么Git添加文件需要</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">add</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">commit</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">一共两步呢？因为</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">commit</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以一次提交很多文件，所以你可以多次</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">add</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">不同的文件</span></div><div><b>3 status  diff   log命令</b></div><div><b> </b> <code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git status</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令可以让我们时刻掌握仓库当前的状态</span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(102, 102, 102);"> </span></span></span></span> <code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git diff</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">顾名思义就是查看difference，可以看看具体修改了什么内容，也可以</span><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git diff HEAD -- 文件名</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令查看工作区和版本库里面最新版本的区别</span></div><div><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git log</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令显示从最近到最远的提交日志，</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">如果嫌输出信息太多，看得眼花缭乱的，可以试试加上</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">--pretty=oneline</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">参数，每次的操作日志显示在一行，但是不显示作者和日期，</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">    而是显示版本号(</span> <span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(250, 250, 250);">commit id</span><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">)和注释</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">和SVN不一样，Git的</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">commit id</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">不是1，2，3……递增的数字，而是一个SHA1计算出来的一个非常大的数字，用十六进制表示</span></div><div><b>4 版本回退</b></div><div><b> </b> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">在Git中，用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">HEAD</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">表示当前版本，</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">上一个版本就是</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">HEAD^</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，上上一个版本就是</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">HEAD^^</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，当然往上100个版本写100个</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">^</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">比较容易数不过来，所以写成</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">HEAD~100</code></div><div>  <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">将当前版本回退到之前的某个版本</span> ，<span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以使用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git reset</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令，比如回退到上一个版本，命令：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><code>$ git re<span style="color: rgb(51, 51, 51); font-weight: bold;">set</span> --hard HEAD^</code></div></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';">该命令还可以回退到任一个版本号，比如：</span></span></span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><code>$ git re<span style="color: rgb(51, 51, 51); font-weight: bold;">set</span> --hard <span style="color: rgb(0, 153, 153);">3628164</span></code></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">版本号没必要写全，前几位就可以了，Git会自动去找。当然也不能只写前一两位，因为Git可能会找到多个版本号，就无法确定是哪一个了</span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(102, 102, 102);">如果已经回退到历史版本，又想恢复到最新版本，仍可以使用此命令，但是如何找到最新版本的版本号呢？</span></span></span></span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Git提供了一个命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git reflog</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">用来记录你的每一次命令，可以根据命令记录来查看版本号，也可用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git log</code></div><div><b>5 工作区和暂存区</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">工作区指被git管理的工作目录</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">工作区有一个隐藏目录</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">.git</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，这个不算工作区，而是Git的版本库</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Git版本库里</span><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">最重要的就是称为stage（或者叫index）的暂存区，还有Git为我们自动创建的第一个分支</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，以及指向</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">的一个指针叫</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">HEAD</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">。</span></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">把文件往Git版本库里添加的时候，是分两步执行的：</span></span></span></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">第一步是用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git add</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">把文件添加进去，实际上就是把文件修改添加到暂存区；</span></span></span></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">第二步是用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git commit</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">提交更改，实际上就是把暂存区的所有内容提交到当前分支。</span></span></span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以简单理解为，需要提交的文件修改通通放到暂存区，然后，一次性提交暂存区的所有修改。</span></div><div><br/></div><div style="margin: 15px 0px; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); font-size: 14px;"><div><img src="git_files/Image.jpg" type="image/jpeg" alt="git-repo" style="cursor: default; height: auto;"/></div></div><div><b>6 git提交的含义</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">每次修改，如果不</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">add</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">到暂存区，那就不会加入到</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">commit</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">中，提交只会将暂存区的的内容提交到当前分支。</span></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><b>7 撤销修改</b></div><div><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git checkout -- 文件名</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以丢弃工作区的修改，</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">让这个文件回到最近一次</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git commit</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">或</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git add</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">时的状态，比如：</span></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">命令</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git checkout -- readme.txt</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">意思就是，把</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">readme.txt</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">文件在工作区的修改全部撤销，这里有两种情况：</span></span></span></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">一种是</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">readme.txt</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">自修改后还没有被放到暂存区，现在，撤销修改就回到和版本库一模一样的状态；</span></span></span></div></div><div style="margin: 15px 0px; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); font-size: 14px;"><div>一种是<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">readme.txt</code>已经添加到暂存区后，又作了修改，现在，撤销修改就回到添加到暂存区后的状态。</div></div></div></div><div><b>8 删除文件</b></div><div><b> </b> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">删除文件有两种方式：</span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';">  一种是用rm(linux命令，相当于本地手动删除文件)再add再commit；</span></span></span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">  一种是用</span></span></span> <span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(250, 250, 250);">git rm 文件名</span><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">命令再commit；</span></span></span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">  用</span></span></span><span style="color: rgb(221, 0, 85); font-family: Consolas, monospace, serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(250, 250, 250);">git rm</span> <span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">命令删除如果未commit，恢复文件需要用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git reset --hard HEAD</code> <span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">命令，如果提交了用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git reset --hard HEAD^</code><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';"><span style="color: rgb(102, 102, 102);">命令(<span style="color: rgb(255, 0, 0);">存疑！！！</span>)</span></span></span></div><div><b>9 远程仓库的创建及第一次与本地内容的关联</b></div><div><span style="color: rgb(68, 68, 68);"><span style="font-family: Consolas, monospace, serif;"><span style="font-size: 12px;">  </span></span></span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Git是分布式版本控制系统，同一个Git仓库，可以分布到不同的机器上。</span></div><div><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;"><span style="color: rgb(102, 102, 102);">可以找一台电脑充当服务器的角色，每天24小时开机，其他每个人都从这个“服务器”仓库克隆一份到自己的电脑上，并且各自把各自的提交推送到服务器仓库里，也从服务器仓库中拉取别人的提交。</span></span></span></div><div><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;"><span style="color: rgb(102, 102, 102);">完全可以自己搭建一台运行Git的服务器，不过现阶段，为了学Git先搭个服务器绝对是小题大作。好在这个世界上有个叫</span><a href="https://github.com/" style="color: rgb(5, 147, 211); text-decoration: none; cursor: pointer; background: transparent;" target="_blank">GitHub</a></span></span><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">的神奇的网站，从名字就可以看出，这个网站就是提供Git仓库托管服务的，所以，只要注册一个GitHub账号，就可以免费获得Git远程仓库。</span></span></span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="color: rgb(102, 102, 102);">以gitHub远程仓库为例，创建一个空仓库后</span></span></span><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">远程库的名字就是</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">origin</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，这是Git默认的叫法，也可以改成别的，但是</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">origin</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">这个名字一看就知道是远程库。</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以把本地库的所有内容推送到远程库上：</span><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><code>$ git push -u origin master</code></div></div></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">把本地库的内容推送到远程，用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git push</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">命令，实际上是把当前分支</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">推送到远程。</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;"><span style="color: rgb(102, 102, 102);">由于远程库是空的，我们第一次推送</span></span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">分支时，加上了</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">-u</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">参数，Git不但会把本地的</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">分支内容推送的远程新的</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">分支，还会把本地的</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">分支和远程的</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">分支关联起来，在以后的推送或者拉取时就可以简化命令。</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">要关联一个远程库，使用命令</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git remote add origin git@server-name:path/repo-name.git</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">；</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;"><span style="color: rgb(102, 102, 102);">关联后，使用命令</span></span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git push -u origin master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">第一次推送master分支的所有内容；</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;"><span style="color: rgb(102, 102, 102);">此后，每次本地提交后，只要有必要，就可以使用命令</span></span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git push origin master</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">推送最新修改；</span></span></span></div><div><b>10 从远程库克隆</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">有了一个远程库，用命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git clone</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">克隆一个本地库：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div><span style="color: rgb(68, 68, 68);"><span style="font-size: 12px;"><code><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(0, 128, 128);">$ </span>git clone </span></code></span></span><font color="#010101" face="Lucida Console" size="1"><span style="font-size:9pt">https://github.com/duxin820/loanTest.git</span></font></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">如果有多个人协作开发，那么每个人各自从远程克隆一份就可以了。</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">GitHub给出的地址不止一个,</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">Git支持多种协议，默认的</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git://</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">使用ssh，但也可以使用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">https</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">等其他协议。</span></div><div><b> </b><b>11 创建与合并分支</b></div><div><b> </b> <code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git checkout</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令加上</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">-b</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">参数表示创建并切换，创建一个已经存在的分支会报错。</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(68, 68, 68);"><code><span style="color: rgb(0, 128, 128);">$ </span>git checkout -b dev<span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';">    //创建dev分支并切换到dev分支</span></span></span></code></span></span></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">  该命令相当于两条命令：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><span style="color: rgb(0, 128, 128);">$ </span>git branch dev    <span style="font-family: monospace;">//创建dev分支</span></div><code><span style="color: rgb(0, 128, 128);">$ </span>git checkout dev  //切换到dev分支</code></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git branch</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令查看当前分支，</span> <code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git branch</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令会列出所有分支，当前分支前面会标一个</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">*</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">号。</span></div><div><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git merge</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令用于合并指定分支到当前分支。</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">合并完成后，就可以放心地删除</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">dev</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">分支了：</span><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git branch -d dev</code></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">因为创建、合并和删除分支非常快，所以Git鼓励你使用分支完成某个任务，合并后再删掉分支，这和直接在</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">master</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">分支上工作效果是一样的，但过程更安全。</span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">当Git无法自动合并分支时，就必须首先解决冲突。解决冲突后，再提交，合并完成。</span></span></span></div><div><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">用</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git log --graph</code><span style="color: rgb(102, 102, 102);"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="font-size: 14px;">命令可以看到分支合并图。</span></span></span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code>$ git log --graph --pretty=oneline --abbrev-commit</code></div><div>通常，合并分支时，如果可能，Git会用<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;">Fast forward</code>模式，但这种模式下，删除分支后，会丢掉分支信息。如果要强制禁用<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">Fast forward</code>模式，Git就会在merge时生成一个新的commit，这样，从分支历史上就可以看出分支信息。</div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">准备合并</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">dev</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">分支，请注意</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">--no-ff</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">参数，表示禁用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">Fast forward</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">：</span></div><div><pre style="margin-top: 15px; margin-bottom: 15px; padding: 10px; background-color: rgb(250, 250, 250); font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap;"><code><span style="color: rgb(0, 128, 128);">$ </span>git merge --no-ff -m <span style="color: rgb(221, 17, 68);">&quot;merge with no-ff&quot;</span> dev</code></pre></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">合并分支时，加上</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">--no-ff</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">参数就可以用普通模式合并，合并后的历史有分支，能看出来曾经做过合并，而</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">fast forward</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">合并就看不出来曾经做过合并。</span></div><div><b>12 储存工作现场</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">Git提供了一个</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">stash</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">功能，可以把当前工作现场“储藏”起来，等以后恢复现场后继续工作</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">当手头工作没有完成时，先把工作现场</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">一下保存到git栈中，然后去修复bug，修复后，再</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash pop</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">，回到工作现场。</span></div><div><pre style="margin-top: 15px; margin-bottom: 15px; padding: 10px; background-color: rgb(250, 250, 250); font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap;"><code><span style="color: rgb(0, 128, 128);">$ </span>git stash</code></pre></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash list</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">命令可以查看git栈中的所有备份。</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">恢复备份有两种方法：</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">一是用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash apply</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">恢复，但是恢复后，stash内容并不删除，你需要用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash drop</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">来删除；</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">另一种方式是用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git stash pop</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">，恢复的同时把stash内容也删了。</span></div><div><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">如果多次stash，恢复的时候，先用<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;">git stash list</code>查看，然后恢复指定的stash，用命令：</p><pre style="margin-top: 15px; margin-bottom: 15px; padding: 10px; background-color: rgb(250, 250, 250); font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap;"><code><span style="color: rgb(0, 128, 128);">$ </span>git stash apply stash@{<span style="color: rgb(0, 153, 153);">0</span>}</code></pre></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">删除一个分支可以使用</span></div><div><pre style="margin-top: 15px; margin-bottom: 15px; padding: 10px; background-color: rgb(250, 250, 250); font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap;"><code><span style="color: rgb(0, 128, 128);">$ </span>git branch -d &lt;分支名&gt;</code></pre></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; white-space: pre-wrap;">如果要丢弃一个没有被合并过的分支，可以通过</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(250, 250, 250);">git branch -D &lt;分支名&gt;</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;">强行删除，此处删除的是本地分支</span></div><div><b>13 本地分支与远程分支关联、push、pull</b></div><div><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">要查看远程库的信息，用<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git remote</code>：</p><pre style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; word-break: break-all; word-wrap: break-word; white-space: pre-wrap; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git remote
origin
</code></pre><p style="margin: 15px 0px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">或者，用<code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">git remote -v</code>显示更详细的信息：</p><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(68, 68, 68);"><code><span style="color: rgb(0, 128, 128);">$ </span>git remote -v<br/>
origin  git<span style="color: rgb(0, 128, 128);">@github</span>.<span style="color: rgb(153, 0, 115);">com:</span>michaelliao/learngit.git (fetch)</code></span></span><div><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(68, 68, 68);">origin  git</span><span style="color: rgb(0, 128, 128);">@github</span><span style="color: rgb(68, 68, 68);">.</span><span style="color: rgb(153, 0, 115);">com:</span><span style="color: rgb(68, 68, 68);">michaelliao/learngit.git (push)</span></span></div></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">上面显示了可以抓取和推送的</span></span></span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; background: rgb(250, 250, 250);">origin</code><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">的地址。如果没有推送权限，就看不到push的地址</span></span></span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);"> 推送分支，就是把该分支上的所有本地提交推送到远程库。推送时，要指定本地分支，这样，Git就会把该分支推送到远程库对应的远程分支上</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><code><span style="color: rgb(0, 128, 128);">$ </span>git push origin dev    //将本地dev分支推送到远程的dev分支上</code></div></div><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue';">将本地存在且远程库不存在的分支推送到远程库使用：</span></span></span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div><span style="color: rgb(68, 68, 68);"><span style="font-size: 12px;"><code><span style="font-family: Consolas, monospace, serif;">$ git push -u origin master </span></code></span></span><code>//远程库不存在分支dev1，此命令将会使远程库新增一个dev1分支且与本地dev1分支关联，需要注意的是：如果本地dev1分支有内容未提交，推送到远程库的dev1分支中也将不包含未提交的内容</code></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">建立本地分支和远程分支的关联，使用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git branch --set-upstream branch-name origin/branch-name</code></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">在本地创建和远程分支对应的分支，使用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git checkout -b branch-name origin/branch-name</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: left; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">，本地和远程分支的名称最好一致。</span></div><div><b>14 标签管理</b></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">打标签：切换到需要打标签的分支上，使用</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git tag &lt;name&gt;</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">就可以打一个新标签：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git tag v1.<span style="color: rgb(0, 153, 153);">0</span></code></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以用命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git tag</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">查看所有标签，</span> <span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">注意，标签不是按时间顺序列出，而是按字母排序的。可以用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git show &lt;tagname&gt;</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">查看标签信息</span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">默认标签是打在最新提交的commit上的。有时候，如果忘了打标签，首先</span><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">找到历史提交的commit id，然后打上就可以了：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div><span style="color: rgb(68, 68, 68);"><span style="font-size: 12px;"><code><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(0, 128, 128);">$ </span>git log --pretty=oneline --abbrev-commit   //查找提交历史</span></code></span></span></div><div><span style="color: rgb(68, 68, 68);"><span style="font-size: 12px;"><code><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(0, 128, 128);">$ </span>git tag v<span style="color: rgb(0, 153, 153);">0</span>.<span style="color: rgb(0, 153, 153);">9</span> <span style="color: rgb(0, 153, 153);">6224937   //对commit id是</span></span></code></span></span><span style="color: rgb(68, 68, 68);"><span style="font-size: 12px;"><code><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(0, 153, 153);">6224937打上标签</span></span></code></span></span></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">还可以创建带有说明的标签，用</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">-a</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">指定标签名，</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">-m</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">指定说明文字：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git tag -a v<span style="color: rgb(0, 153, 153);">0</span>.<span style="color: rgb(0, 153, 153);">1</span> -m <span style="color: rgb(221, 17, 68);">&quot;version 0.1 released&quot;</span> <span style="color: rgb(0, 153, 153);">3628164</span></code></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">用命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git show &lt;tagname&gt;</code><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">可以看到说明文字</span></div><div><p style="margin: 0px 0px 15px; word-wrap: break-word; white-space: pre-wrap; color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);">如果标签打错了，也可以删除：</p><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; overflow: auto; border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(250, 250, 250); background-position: initial initial; background-repeat: initial initial;"><div><span style="font-size: 12px;"><span style="font-family: Consolas, monospace, serif;"><span style="color: rgb(68, 68, 68);"><code><span style="color: rgb(0, 128, 128);">$ </span>git tag -d v<span style="color: rgb(0, 153, 153);">0</span>.<span style="color: rgb(0, 153, 153);">1</span></code></span></span></span></div></div></div><div style="margin: 15px 0px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><div><span style="color: rgb(102, 102, 102);"><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">因为创建的标签都只存储在本地，不会自动推送到远程。所以，打错的标签可以在本地安全删除。</span></span></span></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">如果要推送某个标签到远程，使用命令</span><code style="font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(221, 0, 85); white-space: nowrap; padding: 0px 4px; border: 1px solid rgb(221, 221, 221); border-radius: 3px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);">git push origin &lt;tagname&gt;</code></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git push origin v1.<span style="color: rgb(0, 153, 153);">0</span></code></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">或者，一次性推送全部尚未推送到远程的本地标签：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code>$ git push origin --tags</code></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">如果标签已经推送到远程，要删除远程标签就麻烦一点，先从本地删除：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><div><code><span style="color: rgb(0, 128, 128);">$ </span>git tag -d v<span style="color: rgb(0, 153, 153);">0</span>.<span style="color: rgb(0, 153, 153);">9</span></code></div></div><div><span style="color: rgb(102, 102, 102); font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none; background-color: rgb(255, 255, 255);">然后，从远程删除。删除命令也是push，格式如下：</span></div><div style="margin: 15px 0px; padding: 10px; font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 12px; font-family: Consolas, monospace, serif; color: rgb(68, 68, 68); tab-size: 4; overflow: auto; border: 1px solid rgb(221, 221, 221); border-radius: 3px; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px; background: rgb(250, 250, 250);"><code><span style="color: rgb(0, 128, 128);">$ </span>git push origin <span style="color: rgb(153, 0, 115);">:refs/tags/v0</span>.<span style="color: rgb(0, 153, 153);">9</span></code></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(102, 102, 102);"><br/></span></span></span></span></div><div><span style="font-size: 14px;"><span style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><span style="background-color: rgb(255, 255, 255);"><span style="color: rgb(102, 102, 102);"><br/></span></span></span></span></div></div></div></span>
</div></body></html> 